//
//  BaseURL.swift
//  DaRings
//
//  Created by 尹琼 on 2022/11/25.
//

import UIKit


public enum BaseURL {
    
    case common
    
}

extension BaseURL {
    
    
    public var url: URL {
        switch self {
        case .common:
            if URLEnvironment.current == .debug {
                return URL(string: "https://api.moyoung.com")!
            }
            return URL(string: "https://api.moyoung.com")!
            
            
        }
        
    }
    
}


/// URL 环境
public enum URLEnvironment: Int {
    
    case release = 0
    
    case debug = 1
    
    
}

extension URLEnvironment {
    
    /// debug 环境下后台接口环境本底存储
    private static let URLEnvironmentOfDEBUG: String = "URLEnvironmentOfDEBUG"
    
    public static var current: URLEnvironment {
        
#if DEBUG
        let i = UserDefaults.standard.integer(forKey: URLEnvironmentOfDEBUG)
        guard let cacheURLEnvironment = URLEnvironment(rawValue: i) else {
            return URLEnvironment.debug
        }
        return cacheURLEnvironment
        
#else
        
        return URLEnvironment.release
        
#endif
    }
    
}
